package com.demo;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

public class BeanLifeComponent implements BeanNameAware {
    @Override
    public void setBeanName(String s){
        System.out.println("执行了BeanName："+s);
    }

    //注解方式的初始化方法
    @PostConstruct
    public void doPostConstruct(){
        System.out.println("执行了PostConstruct");
    }

    //xml的初始化方法
    public void myInit(){
        System.out.println("执行了myInit");
    }

    //注解方式的销毁方法
    @PreDestroy
    public void doPreDestroy(){
        System.out.println("执行了PreDestroy");
    }

    public void sayHi(){
        System.out.println("使用Bean");
    }

}
